import cac from 'cac'
import list from './list'
import { name, version } from '../package.json'
import init from './init'

const cli = cac(name)

cli
    .command('<template> [project]', 'Create new project from a template')
    .option('-f, --force', 'Overwrite if the target exists')
    .option('-o, --offline', 'Try to use an offline template')
    // .option('-d, --debug', 'Output detailed exception when exception occurs')
    .allowUnknownOptions() // for prompts override.
    .example('  # with an official template')
    .example(`  $ ${name} <template> [project]`)
    .example('  # with a custom github repo')
    .example(`  $ ${name} <owner>/<repo> [project]`)
    .action(init)

/// 查看所有的项目模板
cli
    .command('list [owner]', 'Show all available templates')
    .alias('ls')  // 命令别名
    .option('-j, --json', 'Output with json format')
    .option('-s, --short', 'Output with short format')
    .action(list)

cli.command('version').action(() => {
    console.log(`当前版本${version}`);
})


cli.help().version(version).parse()